package com.mk.settlement.task.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.mk.settlement.service.SchedulerService;
import com.mk.settlement.service.SettlementRegularService;
import com.mk.settlement.task.SettlementTaskJob;

/**
 * 周结算计划任务服务类.
 * 
 * @author chuaiqing.
 *
 */
@Service(value = "settlementWeekTaskJob")
public class SettlementWeekTaskJob implements SettlementTaskJob {

    /**
     * 注入周结算service
     */
    @Autowired
    @Qualifier(value = "settlementWeekService")
    private SettlementRegularService weekService;

    @Autowired
    @Qualifier(value = "schedulerService")
    private SchedulerService schedulerService;

    private static final String TASK_NAME = "周结结算定时任务";

    /**
     * 
     */
    @Override
    public void execute() {

        if (schedulerService.havePermission(TASK_NAME)) {
            log.info("周结  execute at: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            // 生成周结算数据
            weekService.doSettlement();

        } else {
            log.info("没有获得" + TASK_NAME + "运行权限.");
        }
    }

}
